<template>
    <div>
        <!-- <el-breadcrumb separator-class="el-icon-arrow-right">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>导演管理</el-breadcrumb-item>
            <el-breadcrumb-item>导演列表</el-breadcrumb-item>
        </el-breadcrumb> -->
        <!-- <el-divider content-position="center"></el-divider> -->

        <el-form :inline="true" :model="formInline" class="demo-form-inline" @submit.native.prevent>
            <el-form-item label="姓名">
                <el-input @keyup.native.enter="onSubmit" v-model="formInline.name" placeholder="输入姓名:模糊查询"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="onSubmit">查询</el-button>
            </el-form-item>
        </el-form>

        <person @delete="deleteItem(item.id)" v-for="item in directors" :key="item.id" :avatar="item.director_avatar"
            :name="item.director_name">
        </person>
    </div>
</template>

<script>

import person from '@/components/Person.vue'
export default {
    inject: ['reload'],
    components: {
        person
    },
    data() {
        return {
            formInline: {
                name: '',
            },
            directors: []
        }
    },
    methods: {
        onSubmit() {
            this.$http.directorApi.queryByNameLike(this.formInline).then(res => {
                this.directors = res.data.data;
            }).catch(err => {
                console.log(err);
            })
        },
        deleteItem(id) {
            this.$confirm('此操作将永久删除此项, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.$http.directorApi.delete({ id }).then(res => {
                    if (res.data.code == 200) {
                        this.$message({
                            type: 'success',
                            message: '删除成功!'
                        });
                        this.reload()
                    }
                })
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                });
            });
        },
    },
    mounted() {
        this.$http.directorApi.queryAll().then(res => {
            this.directors = res.data.data;
        }).catch(err => {
            console.log(err);
        })
    }
}
</script>

<style lang="scss" scoped>

</style>